# Import the 'get_zt_user_id' function from the 'myapp.project' module.
# This function is responsible for retrieving the zhentong user ID associated with a given user ID.
from myapp.project import get_zt_user_id
# Import the 'NODE_LABEL_KEY' constant from the 'myapp.third.zhentong.api' module.
# This constant likely represents a key used for labeling nodes in a system, possibly related to zhentong.
from myapp.third.zhentong.api import NODE_LABEL_KEY


# Define a function named 'get_node_selector' that takes one argument: 'user_id'.
# This function aims to determine the appropriate node selector based on the provided user ID.
def get_node_selector(user_id):
    # Call 'get_zt_user_id' with the given 'user_id' to retrieve the corresponding zhentong user ID.
    zt_user_id = get_zt_user_id(user_id)
    # Check if the retrieved 'zt_user_id' is None.
    # A None value indicates that a zhentong user was not found for the given 'user_id'.
    if zt_user_id is None:
        # If no zhentong user is found, raise an Exception with a descriptive error message.
        raise Exception(f"zhengtong user not found for user_id: {user_id}")
    # If a zhentong user ID is found, return a dictionary that represents a node selector.
    # The key of the dictionary is 'NODE_LABEL_KEY' and its value is the string representation of 'zt_user_id'.
    # This dictionary is likely used to select a specific node in a cluster or system based on the zhentong user ID.
    return {NODE_LABEL_KEY: str(zt_user_id)}
